//
//  submitViewController.m
//  ZPSALE
//
//  Created by tmosport on 14-7-5.
//  Copyright (c) 2014年 tmosport. All rights reserved.
//

#import "submitViewController.h"
#import "alipayViewController.h"

@interface submitViewController ()
@property(nonatomic,strong)NSString *orderSn;
@property(nonatomic,strong)NSString *needPay;
@property(nonatomic,strong)NSString *payType;
@property(nonatomic,strong)NSString *shipingTime;
@property(nonatomic,strong)NSString *memInfo;
@property(nonatomic,assign)NSInteger payTypeId;
@end

@implementation submitViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"提交成功";
    _payTypeId = [[_orderInfo objectAtIndex:5] intValue];
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]
                                            initWithTitle:@"继续购物"
                                            style:UIBarButtonItemStyleBordered
                                            target:self
                                            action:@selector(toFinish)];
    
    if (_payTypeId ==2 && _payStatus !=1) {
        _aplyButton.hidden = NO;
        _aplyButton.backgroundColor = ColorFromRGB(0xff0100);
        _aplyButton.layer.cornerRadius = 4.0f;
        _aplyButton.clipsToBounds = YES;
    } else {
        _aplyButton.hidden = YES;
    }
}


-(void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}
-(void)toFinish{
    [self.navigationController popToRootViewControllerAnimated:NO];
    [self.tabBarController setSelectedIndex:4];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger sections;
    sections = 2;
    return sections;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger rows;
    rows = section > 0 ? 1 : 5;
    return rows;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat cellHeight;
    if (indexPath.section ==1) {
        cellHeight = 72;
    }else{
        cellHeight = 44;
    }
    return cellHeight;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSArray *cellHeader = [NSArray arrayWithObjects:@"订单编号:",@"应付金额:",@"支付方式:",@"配送时间:",@"备注:", nil];
    
    UITableViewCell *cell;
    if (indexPath.section == 0) {
        cell = nil;
        cell = [tableView dequeueReusableCellWithIdentifier:@"reuseCell"];
        UILabel *headerTitle = (UILabel *)[cell viewWithTag:1001];
        UILabel *headerContent = (UILabel *)[cell viewWithTag:1002];
        headerTitle.text = [cellHeader objectAtIndex:indexPath.row];
        headerContent.text = [_orderInfo objectAtIndex:indexPath.row];
    }
//    else if(indexPath.section == 1){
//        cell = nil;
//        if (_payTypeId ==2 && _payStatus !=1) {
//            cell = [tableView dequeueReusableCellWithIdentifier:@"payCell"];
//        }else{
//            cell = [tableView dequeueReusableCellWithIdentifier:@"infoCell"];
//        }
//    }
    else{
        cell = nil;
         cell = [tableView dequeueReusableCellWithIdentifier:@"infoCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)aplyButtonClicked:(UIButton *)sender {
    if (_payTypeId ==2) {
        alipayViewController *aliPayVc = [self.storyboard instantiateViewControllerWithIdentifier:@"alipayViewController"];
        aliPayVc.memberId = _memberId;
        aliPayVc.token = _token;
        aliPayVc.orderId = [_orderInfo objectAtIndex:6];
        aliPayVc.ordersn = [_orderInfo objectAtIndex:0];
        aliPayVc.needpay =[_orderInfo objectAtIndex:1];
        //        aliPayVc.hidesBottomBarWhenPushed = YES;
        //        [self.navigationController pushViewController:aliPayVc animated:YES];
        UINavigationController *navigationVC = [[UINavigationController alloc]initWithRootViewController:aliPayVc];
        navigationVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        navigationVC.navigationBar.tintColor = [UIColor blackColor];
        // present
        [self presentViewController:navigationVC animated:YES completion:nil];
        
    }
    
}
@end
